package dao;

import bean.User;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import utils.JDBCUtils;

import java.sql.SQLException;

public class DaoUserlmpl implements DaoUser {
    @Override
    public User login(User user) {
        QueryRunner queryRunnery = new QueryRunner(JDBCUtils.getDataSource());
        String sql = "SELECT * FROM users WHERE username =? and password = ?";
        User existUser = null;
        try {
            existUser = queryRunnery.query(sql,new BeanHandler<User>(User.class),
                    user.getUserName(),user.getPassword());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return existUser;
    }
}
